package com.sword.pay;

import com.sword.common.strategy.ISCommonStrategy;
import com.sword.pay.bean.enums.ChannelPayEnum;
import com.sword.pay.repository.config.ISPayClientConfig;

import java.util.HashMap;

/**
 * @description: 管理
 * @author：Lv.RJ
 * @version: 1.0.0
 * @create: 2025/02/17
 **/
public class PayManager<T> {
    /**
     * 开票设备组件组件
     */
    private volatile static HashMap<String, Object> driverStrategyHashMap = new HashMap<>();

    /**配置信息*/
    private volatile static HashMap<String, Object> configHashMap = new HashMap<>();

    /**
     * 设备缓存
     * @param invoiceDriverRepository 开票实现设备
     */
    public static void setISInvoiceDriverRepository(ISCommonStrategy invoiceDriverRepository) {
        if (invoiceDriverRepository != null) {
            driverStrategyHashMap.put(invoiceDriverRepository.getChannelCode(),invoiceDriverRepository);
        }
    }


    public static <T> T getISInvoiceDriverRepository(ChannelPayEnum channelEnum, Class<T> clazz) {
        return (T)driverStrategyHashMap.get(channelEnum.getCode());
    }



    /**
     * 设备缓存
     * @param object 动态代理配置信息类
     */
    public static void setBeanConfig(ISPayClientConfig object) {
        if (object != null) {
            configHashMap.put(object.getChannelCode().getCode(),object);
        }
    }


    public static <T> T getBeanConfig(ChannelPayEnum channelPayEnum, Class<T> clazz) {
        return (T)configHashMap.get(channelPayEnum.getCode());
    }

    public static <T> T getBeanConfig(String channelPayEnumCode, Class<T> clazz) {
        return (T)configHashMap.get(channelPayEnumCode);
    }
}
